const mongoose = require('mongoose');
const setting = require('../setting');
const crypto  = require('crypto');

//这句话说明我们使用的promise对象是ES6中原生的promise对象.
mongoose.Promise = global.Promise;

mongoose.connect('mongodb://localhost/liTao');
const DbSet = {
    encrypt: function(data, key) { // 密码加密
        let cipher = crypto.createCipher("bf", key);
        let newPsd = "";
        newPsd += cipher.update(data, "utf8", "hex");
        newPsd += cipher.final("hex");
        return newPsd;
    },

//    增加一条数据
    addOne:function (req,res,Model,data) {
        let newObj = new Model(data);
        newObj.save().then((user) => {
            res.end('success');
    }).catch((err) => {
            res.end(err);
    })
    },

}



module.exports = DbSet
